package com.lelouch.concurrency.example.syncContainer;

import com.lelouch.concurrency.annotation.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.Iterator;
import java.util.Vector;

/**
 * Vector2
 *
 * @author lcy
 * @create 2018-05-25 14:38
 */
@Slf4j
@NotThreadSafe
public class VectorExample3 {
    private static Vector<Integer> vector = new Vector<>();

    public static void main(String[] args) {
        vector.add(1);
        vector.add(2);
        vector.add(3);
        test3();
    }

    public static void test1() {
        for (Integer i : vector) {
            if (i.equals(3)) {
                vector.remove(i);
            }
        }
    }

    public static void test2() {
        Iterator<Integer> iterator = vector.iterator();
        while (iterator.hasNext()){
            Integer i = iterator.next();
            if (i.equals(3)) {
                vector.remove(i);
            }
        }

    }

    public static void test3() {
        for (Integer i=0;i<vector.size();i++) {
            if (i.equals(3)) {
                vector.remove(i);
            }
        }
    }

}
